﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.Quantify
{
    public partial class lp_Package : System.Web.UI.Page
    {
        public StringBuilder sb = new StringBuilder();//套餐
        public StringBuilder sb1 = new StringBuilder();//
        public string depttype = "";
        string deptlist = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            
             depttype = ZLDC.Topo.BLL.Estate.lp_Report_list.GetType(_Utility.GetInfoBySession().m_sDeptID);//获取部门类型
              hiddeptid.Value = _Utility.GetInfoBySession().m_sDeptID;
             if (depttype == "营业部")
             {
                 deptlist = _Utility.GetInfoBySession().m_sDeptID;
             }
             else
             {
                 deptlist = ZLDC.Topo.BLL.Estate.lp_Basis.GetDeptList(_Utility.GetInfoBySession().m_sDeptID);
              
                
             }
            if (!IsPostBack)
            {
               
                ZLDC.Topo.BLL.Estate.lp_Package.GetDrop(dropPK,RpList,_Utility.GetInfoBySession().m_sUserID,depttype);
                string a = dropPK.SelectedItem.Text;
                txtTotal1.Value = ZLDC.Topo.BLL.Estate.lp_Basis.Exists_Set();//获取最低分数
                txtTotal2.Value = txtTotal1.Value;
                GetBtnvb(depttype);
            }
        }


        /// <summary>
        /// 生效按钮显示
        /// </summary>
        /// <param name="depttype"></param>
        protected void GetBtnvb(string depttype)
        {
            ZLDC.Topo.BLL.Estate.lp_Package.GetBtnvb(_Utility.GetInfoBySession().m_sUserID, depttype, btnDetermine, btnCantel,Panel1,Panel2);
        }
       

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            btnNone();
           
        }
        protected void btnNone()
        {
            if (depttype == "营业部" || depttype == "区域")
            {
                if (ZLDC.Topo.BLL.Estate.lp_Package.GetSJTCcount1(_Utility.GetInfoBySession().m_sDeptID) > 0)
                {
                    return;
                }
            }
            divnewName.Style["display"] = "block";
            Button1.Visible = false;
            Button2.Visible = false;
            btnDetermine.Visible = false;
            btnCantel.Visible=false;
            btnAdd.Visible = true;
            LinkButton2.Visible = true; 
            LinkButton1.Visible = false; 
            sptc.Visible = false;
            Panel2.Visible = false;
            Panel1.Visible = true;
            DataSet ds = new DataSet();
            if (ZLDC.Topo.BLL.Estate.lp_Package.GetSJTCcount(_Utility.GetInfoBySession().m_sDeptID)>0)//上级如有默认套餐就跳转
            {
                Response.Redirect("Package/lp_PackageSet.aspx");
            }
            else
            {
                ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds("select * from lp_Basis");
            }
            Repeater1.DataSource = ds.Tables[0];
            Repeater1.DataBind();
        }

        protected void dropPK_SelectedIndexChanged(object sender, EventArgs e)
        {
            Panel2.Visible = dropPK.SelectedValue == "0" ? false : true;
            ZLDC.Topo.BLL.Estate.lp_Package.GetTb(dropPK, RpList, _Utility.GetInfoBySession().m_sDeptID, depttype, hiduserid);
          
                if (dropPK.SelectedValue == "0")
                {
                    txttext.Text = "";
                    txtallnum1.Value = "0";
                    txtallnum2.Value = "0";
                }
                else
                {
                    int i = 0;
                    if (dropPK.SelectedItem.Text.IndexOf("营业部") != -1 || depttype == "营业部")
                    {
                        i++;
                        txttext.Text ="";
                        hidcount.Value = "1";
                    }
                    else
                    {
                        txttext.Text = dropPK.SelectedItem.Text;
                    }
                    if (i== 0)
                    {
                        if (dropPK.SelectedItem.Text.IndexOf("区域") != -1 || depttype == "区域")
                        {
                            txttext.Text = "";
                            hidcount.Value = "1";
                        }
                        else
                        {
                            txttext.Text = dropPK.SelectedItem.Text;
                        }
                    }
                   
                }
                
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            ZLDC.Topo.BLL.Estate.lp_Package.BtnUpdate(dropPK, RpList, Page, hidcount, txttext,depttype,hiduserid);
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            Response.Redirect(Request.RawUrl);
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            ZLDC.Topo.BLL.Estate.lp_Package.BtnAdd(txtName,Repeater1,this.Page,depttype);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            ZLDC.Topo.BLL.Estate.lp_Package.Btn2(dropPK,this.Page,hiduserid);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        //Eval("CompleteNum"数量),Eval("Point"分值),Eval("Score"最高分)Quantity
        protected int GetHeiht(object CompleteNum, object Point, object Score, object Quantity, object Choose)
        {
            if (Choose.ToString() == "1")
            {
                if (int.Parse(Score.ToString()) == 0)
                {
                    decimal total = (Convert.ToDecimal(Point.ToString()) / Convert.ToDecimal(CompleteNum.ToString()) * Convert.ToDecimal(Quantity.ToString()));
                    int fk = int.Parse(Math.Round(total).ToString());
                    return fk;
                }
                else
                {
                    decimal total = (Convert.ToDecimal(Point.ToString()) / Convert.ToDecimal(CompleteNum.ToString()) * Convert.ToDecimal(Quantity.ToString()));
                    int fk=int.Parse(Math.Round(total).ToString());
                    if (total > int.Parse(Score.ToString()))
                    {
                        return int.Parse(Score.ToString());

                    }
                    else
                    {
                        return fk;
                    }
                }
            }
            else
            {
                return 0;
            }
        }
    }
}
